﻿@model IList<SampleData>
@using Stardust.Data.Monitors
@using NewLife;
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using XCode.Membership;
@using NewLife.Cube;
@using System.Web;
@{
    var page = ViewBag.Page as Pager;
}
@if (!page["traceId"].IsNullOrEmpty() && Model.Count > 0)
{
    await Html.RenderPartialAsync("_CallChain", Model);
}
<table class="table table-bordered table-hover table-striped table-condensed">
    <thead>
        <tr>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("AppId"))">应用</a></th>
            <th class="text-center" title="操作名。接口名或埋点名"><a href="@Html.Raw(page.GetSortUrl("Name"))">操作名</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Success"))">正常</a></th>
            <th class="text-center" style="min-width:134px;" title="开始时间。Unix毫秒"><a href="@Html.Raw(page.GetSortUrl("StartTime"))">开始时间</a></th>
            <th class="text-center" style="min-width:134px;" title="结束时间。Unix毫秒"><a href="@Html.Raw(page.GetSortUrl("EndTime"))">结束时间</a></th>
            <th class="text-center" title="耗时。毫秒"><a href="@Html.Raw(page.GetSortUrl("Cost"))">耗时</a></th>
            <th title="跨多系统查看调用链">追踪</th>
            <th class="text-center" title="追踪标识。可用于关联多个片段，建立依赖关系，随线程上下文、Http、Rpc传递"><a href="@Html.Raw(page.GetSortUrl("TraceId"))">追踪标识</a></th>
            <th class="text-center" title="唯一标识。随线程上下文、Http、Rpc传递，作为内部片段的父级"><a href="@Html.Raw(page.GetSortUrl("SpanId"))">唯一标识</a></th>
            <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("ParentId"))">父级标识</a></th>
            @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
            {
                <th class="text-center">操作</th>
            }
        </tr>
    </thead>
    <tbody>
        @foreach (var entity in Model)
        {
            var url1 = $"appDayStat?appId={entity.AppId}";
            var url2 = $"traceDayStat?appid={entity.AppId}&name={HttpUtility.UrlEncode(entity.Name)}";
            var color2 = "";
            if (entity.Name.StartsWithIgnoreCase("db:"))
            {
                color2 = "orange";
            }
            else if (entity.Name.StartsWithIgnoreCase("mq:", "redismq:", "mqtt:", "mns:", "emq:"))
            {
                color2 = "mediumpurple";
            }
            else if (entity.Name.StartsWithIgnoreCase("redis:"))
            {
                color2 = "palevioletred";
            }
            <tr>
                <td class="text-center"><a href="@url1" title="应用最近的监控图表">@entity.AppName</a></td>
                <td title="@entity.Tag" style="max-width:400px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;"><a href="@url2" style="color: @color2">@entity.Name</a></td>
                <td class="text-center">
                    <i class="glyphicon glyphicon-@(entity.Success ? "ok" : "remove")" style="color: @(entity.Success ? "green" : "red");"></i>
                </td>
                <td class="text-center" title="@entity.StartTime">@entity.Start.ToFullString("")</td>
                <td class="text-center" title="@entity.EndTime">@entity.End.ToFullString("")</td>
                <td class="text-right">@entity.Cost.ToString("n0")</td>
                <td><a href="?traceId=@entity.TraceId" title="跨多系统查看调用链">追踪</a></td>
                <td><a href="?traceId=@entity.TraceId">@entity.TraceId</a></td>
                <td>@entity.SpanId</td>
                <td>@entity.ParentId</td>
                @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                {
                    <td class="text-center">
                        @await Html.PartialAsync("_List_Data_Action", (Object)entity)
                    </td>
                }
            </tr>
        }
    </tbody>
</table>